﻿@model BankCreditPortfolio.Models.ClientCabinetModels.DrawOrderModel
@using BankCreditPortfolio.DAL.Entities
@using BankCreditPortfolio.DAL.Services
@{
    ViewBag.Title = "Draw Order";
}
<strong>Draw Order</strong>
<p>
    Use the form below to draw new credit order.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/Styles/forms.css")" rel="stylesheet" type="text/css" />
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data", @id = "formid" }))
{
    @Html.ValidationSummary(true, "Order creation was unsuccessful. Please correct the errors and try again.")
    <script type="text/javascript">
        $(function () {
            $("#dropdownid").change(function () {
                if ($("#dropdownid option:selected").attr("num") > 0) {
                    $("#guarantorFields").show();
                }
                else {
                    $("#guarantorFields").hide();
                }
                $("#currencyName").html($("#dropdownid option:selected").attr("currency"));
                $("#min").html($("#dropdownid option:selected").attr("min"));
                $("#max").html($("#dropdownid option:selected").attr("max"));
            });
        });
        $(document).ready(function () {
            if ($("#dropdownid option:selected").attr("num") > 0) {
                $("#guarantorFields").show();
            }
            else {
                $("#guarantorFields").hide();
            }
            $("#currencyName").html($("#dropdownid option:selected").attr("currency"));
            $("#min").html($("#dropdownid option:selected").attr("min"));
            $("#max").html($("#dropdownid option:selected").attr("max"));

            $('#formid').submit(function () {
                if ($('#formid').validate().errorList.length == 0) {
                    $('#drawOrderButton').attr('disabled', true);
                }
            });
        });
    </script>
    <div>
        <fieldset>
            <legend>Order Information</legend>
            <div class="editor-label">
                @Html.LabelFor(m => m.TariffTitle)
            </div>
            <div class="editor-field">
				@*sorry for hooks oO*@
				<select id="dropdownid" name="TariffTitle" class="valid">
					@{
                        var tariffTitle = Model.SelectedTariff;// ViewData["SelectedTariff"];
                        var tariffs = Model.Tariffs;// (IEnumerable<Tariff>)ViewData["Tariffs"];
						foreach (Tariff tariff in tariffs)
						{
                            if (tariff.Title.Equals(tariffTitle))
                            {
                                <option value="@tariff.Title" num="@tariff.NumberOfGuarantors" currency="@tariff.Currency.Title" min="@tariff.Min" max="@tariff.Max" id="@tariff.TariffId" selected="selected">@tariff.Title</option>
                            }
                            else
                            {
                                <option value="@tariff.Title" num="@tariff.NumberOfGuarantors" currency="@tariff.Currency.Title" min="@tariff.Min" max="@tariff.Max" id="@tariff.TariffId">@tariff.Title</option>
                            }
                        }
					}
				</select>
                @*@Html.DropDownList("dropdownid", (SelectList)ViewBag.Tariffs))*@
			</div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Amount) (the sum between <span id="min"></span> and <span id="max"></span> in <span id="currencyName"></span>)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.Amount)
                @Html.ValidationMessageFor(m => m.Amount)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Gains)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.Gains)
                @Html.ValidationMessageFor(m => m.Gains)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.GainCurrencies)
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(m => m.GainCurrencyId, new SelectList(Model.GainCurrencies, "CurrencyId", "Title"))
            </div>
            <div class="editor-label" style="font-weight: normal;">
                @Html.LabelFor(m => m.Documents)
            </div>
            <div class="editor-field">
                <input type="file" name="file" id="file" />
                @Html.ValidationMessageFor(m=>m.Documents)
            </div>
        </fieldset>
        <div id="guarantorFields" class="guarantorFields">
            <fieldset>
                <legend>Guarantor Information</legend>
                <div class="editor-label">
                    @Html.LabelFor(m => m.FirstName)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.FirstName)
                    @Html.ValidationMessageFor(m => m.FirstName)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.LastName)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.LastName)
                    @Html.ValidationMessageFor(m => m.LastName)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.MiddleName)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.MiddleName)
                    @Html.ValidationMessageFor(m => m.MiddleName)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.PersonalId)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.PersonalId)
                    @Html.ValidationMessageFor(m => m.PersonalId)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.PassportDate)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.PassportDate, new { @id = "datefield", autocomplete = "off" })
                    @*<input class="datefield" data-val="true" data-val-required="Passport date is required."  id="PassportDate" name="PassportDate" type="text" value=@DateTime.Now />*@
                    @Html.ValidationMessageFor(m => m.PassportDate)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.PassportIssuingAuthority)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.PassportIssuingAuthority)
                    @Html.ValidationMessageFor(m => m.PassportIssuingAuthority)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.Address)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.Address)
                    @Html.ValidationMessageFor(m => m.Address)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.Phone)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.Phone)
                    @Html.ValidationMessageFor(m => m.Phone)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.Workplace)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.Workplace)
                    @Html.ValidationMessageFor(m => m.Workplace)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m => m.GuarantorGains)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.GuarantorGains)
                    @Html.ValidationMessageFor(m => m.GuarantorGains)
                </div>
                 <div class="editor-label">
                @Html.LabelFor(m => m.GuarantorCurrencies)
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(m => m.GuarantorCurrencyId, new SelectList(Model.GuarantorCurrencies, "CurrencyId", "Title"))
            </div>
            </fieldset>
        </div>
        <p>Fields marked <b>bold</b> are required</p>
        <p>
            <input type="submit" id="drawOrderButton" value="Draw Order"/>
        </p>
    </div>
}
